import { Bounds } from "laya/d3/math/Bounds";
import { Matrix4x4 } from "laya/maths/Matrix4x4";
import { Vector2 } from "laya/maths/Vector2";
import { IBufferState } from "laya/RenderDriver/DriverDesign/RenderDevice/IBufferState";
import { ShaderData } from "laya/RenderDriver/DriverDesign/RenderDevice/ShaderData";
import { SubShader } from "laya/RenderEngine/RenderShader/SubShader";

export enum GCARenderMask {
    Normal = 1,
    CastShadow = 2,
    ReceiveShadow = 4
}

export class GCARenderGeometrtElement {//对应subMesh架构
    indexCount: number;
    indexFormat: number;
    indexOffset: number;
    bufferState: IBufferState;
}

export class BatchElement {//对应一个渲染批次
    subMeshIdx: number;
    matIdx: number;
}

export class IGCAMaterialData {//对应一个Material
    id: number;
    shaderData: ShaderData;
    subShader: SubShader;
    renderQueue: number;
    cull: number;
}

export interface batchIDInfo {
    res: GCAResData,
    islower: QXLodLevel,
    elementIndex: number,
    isReceiveShadow: boolean
    lightmapIndex: number,
    flipped: boolean
}
export class GCAResData {//对应一个Ins对应的渲染资源
    static _countPtr: number = 0;
    static _resDataMap: Map<number, GCAResData> = new Map();
    static _batchIDMap: Map<number, batchIDInfo> = new Map();
    static getResDataById(id: number) {
        return this._resDataMap.get(id);
    }
    constructor() {
        this.id = GCAResData._countPtr++;
        GCAResData._resDataMap.set(this.id, this);
    }
    id: number;
    isDirty: boolean = false;
    materials: IGCAMaterialData[] = [];
    batchElements: BatchElement[] = [];
    mesh: GCARenderGeometrtElement[] = [];
    meshid: number;
    haslowerMat: boolean;
    lowermat: IGCAMaterialData;
    lowerMeshId: number;
    lowerMeshGeometry: GCARenderGeometrtElement;
}

export class IGCABVHCell {//一个渲染节点
    static _countPtr: number = 0;
    static _InsDataMap: Map<number, IGCABVHCell> = new Map();
    static getInsDataById(id: number) {
        return this._InsDataMap.get(id);
    }
    constructor() {
        this.id = IGCABVHCell._countPtr++;
        IGCABVHCell._InsDataMap.set(this.id, this);
    }
    id: number;
    worldMatrix: Matrix4x4;
    resId: number;
    bounds: Bounds;
    hasLower: boolean;
    renderMask: number;
    flipped: boolean;
    lightmapIndex: number;
    customData: Record<string, any> = {};
    customDataArray: Float32Array;
    loadMask: number;//需要看Agent中有多少层的
    loadMaskRange: Vector2 = new Vector2(0, 1000);
}

export enum QXLodLevel {//渲染节点的lod等级
    High = 0,
    Lower = 1
}

export enum CullingMode {//裁剪模式
    Forward,
    ShadowDir,
    ShadowSpot
}

